﻿Public Class StockVaccins_CTRL
    Implements IDisposable

    Private _EDM As AniFormEntities
    Private _listeVaccins As List(Of Vaccins)
    Private _listeVaccinsMaJ As List(Of Vaccins)

#Region "Cycle de vie du controleur StockVaccins"

    Public Sub New(ByVal edm As AniFormEntities)
        _EDM = edm
        _listeVaccins = New List(Of Vaccins)
        _listeVaccinsMaJ = New List(Of Vaccins)
        setListeVaccins()
    End Sub

    Private disposedValue As Boolean = False        ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
            End If
            _EDM.Dispose()
            For Each element In _listeVaccins
                element = Nothing
            Next
            _listeVaccins.Clear()
            _listeVaccins = Nothing
            For Each element In _listeVaccinsMaJ
                element = Nothing
            Next
            _listeVaccinsMaJ.Clear()
            _listeVaccinsMaJ = Nothing
        End If
        Me.disposedValue = True
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

#End Region

    Private Sub setListeVaccins()
        Dim requete As IEnumerable(Of Vaccins) = (From unVaccin In _EDM.Vaccins _
                                                   Select unVaccin)
        _listeVaccins.AddRange(requete.ToList)
    End Sub

    Public ReadOnly Property getListeVaccins()
        Get
            Return _listeVaccins
        End Get
    End Property

    Public Sub setNouveauStock(ByVal vaccin As Vaccins, ByVal qte As Integer)
        vaccin.QuantiteStock = qte
        _listeVaccinsMaJ.Add(vaccin)
    End Sub

    Public Sub maJStockVaccins()
        For Each Vaccins In _listeVaccinsMaJ
            _EDM.SaveChanges(True)
        Next
    End Sub


End Class
